package com.graduation.project.controller.process;

import com.graduation.project.entity.dto.DeleteFileDTO;
import com.graduation.project.entity.dto.UploadFileDTO;
import com.graduation.project.entity.dto.task.ListTaskDTO;
import com.graduation.project.entity.dto.UpdateStatusDTO;
import com.graduation.project.service.process.OpenReportService;
import com.graduation.project.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/openReport")
public class OpenReportController {

    @Autowired
    private OpenReportService openReportService;

    /**
     * 查询开题报告列表数据
     * @param input 查询开题报告输入类
     * @return ResultUtil
     */
    @PostMapping("/post/listOpenReportByCondition")
    public ResultUtil<?> listOpenReportByCondition(@RequestBody ListTaskDTO input) {
        return openReportService.listOpenReportByCondition(input);
    }

    /**
     * 编辑（上传）开题报告
     * @param input 上传文件输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:openReport:update')")
    @PostMapping("/post/uploadOpenReportFile")
    public ResultUtil<?> uploadOpenReportFile(UploadFileDTO input) {
        return openReportService.uploadOpenReportFile(input);
    }

    /**
     * 删除开题报告
     * @param input 删除文件输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:openReport:update')")
    @PutMapping("/put/deleteOpenReportFile")
    public ResultUtil<?> deleteOpenReportFile(@RequestBody DeleteFileDTO input) {
        return openReportService.deleteOpenReportFile(input);
    }

    /**
     * 教师审核
     * @param input 审核输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:openReport:teacherAudit')")
    @PutMapping("/put/teacherAuditOpenReport")
    public ResultUtil<?> teacherAuditOpenReport(@RequestBody UpdateStatusDTO input) {
        return openReportService.teacherAuditOpenReport(input);
    }

    /**
     * 主任审核
     * @param input 审核输入类
     * @return ResultUtil
     */
    @PreAuthorize("hasAnyAuthority('pro:openReport:directorAudit')")
    @PutMapping("/put/directorAuditOpenReport")
    public ResultUtil<?> directorAuditOpenReport(@RequestBody UpdateStatusDTO input) {
        return openReportService.directorAuditOpenReport(input);
    }

    /**
     * 获取审核信息
     * @param id 开题报告id
     * @return ResultUtil
     */
    @GetMapping("/get/getAuditMessage")
    public ResultUtil<?> getAuditMessage(@RequestParam("id") Long id) {
        return openReportService.getAuditMessage(id);
    }
}
